


#include<cassert>
#include<iostream>
#include<vector>

class RuleOfFive {

	//Rule 1
	//拷贝构造函数 
	RuleOfFive(const RuleOfFive &rhs) : m_value(new int(*(rhs.m_value))){}
	//Rule 2
	//右值引用拷贝构造函数, = delete 告诉编译器，不实现
	RuleOfFive(RuleOfFive&& rhs)= delete ;

	//Rule 3
	RuleOfFive &operator=(const RuleOfFive	&rhs){
		*m_value=rhs.m_value;
		return *this;
	}
	//Rule 4
	RuleOfFive &operator=(RuleOfFive&& rhs){
		if(&rhs==this) return *this;
		delete m_value;
		m_value=rhs.m_value;
		return *this;
	}

	//Rule 5
	~RuleOfFive(){
		delete m_value;	
	}

	void print()const{
		//尽量避免 一下写法,出现if判断，这样写是逻辑错误，m_value 是
		//如果非非法，就不应该打印，因为出现错误，才需要被打印
		//if(m_value){
		//	std::cout<<*m_value<<std::endl;
		//}

		//应该使用如下写法
		//assert()编译有问题，则会报错
		assert(m_value);
		std::cout<<*m_value<<std::endl;

	}


}
